package hero.mps.web.sys_role_menu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import hero.mps.web.sys_role.mapper.SysRoleMapper;
import hero.mps.web.sys_role_menu.entity.SysRoleMenu;
import hero.mps.web.sys_role_menu.mapper.SysRoleMenuMapper;
import hero.mps.web.sys_role_menu.service.SysRoleMenuService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {
    @Override
    @Transactional
    public boolean saveRoleMenu(Integer roleId, List<Integer> menuIds) {
        // 先删除再插入
        QueryWrapper<SysRoleMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SysRoleMenu::getRoleId, roleId);
        // 删除
        this.baseMapper.delete(queryWrapper);
        // 插入
        return this.baseMapper.saveRoleMenu(roleId, menuIds);
    }
}
